import React from 'react'
import { SchemaForm, Item, Observer } from '@amazebird/antd-schema-form'

const schema = {
  user: {
    label: '用户名',
    component: 'Input'
  },
  test:{
    label:'选择联动',
    component:'Input',
    value:Observer({
      watch:['user','#type'],
      filter:([user,type])=>{
        console.info('filter',user,type)
        return true
      },
      action:([user,type])=>{
        return `${user}--棒棒哒`
      }
    })
  }
}

// function useObserver
function Demo() {
  const form = SchemaForm.createForm()

  function setName(type){
    if(type===1){
      form.setFields([{name:['user'],value:'aaa'}])
      form.setState({type})
    }else{
      form.setFields([{name:['user'],value:'bbb'}])
      form.setState({type})
    }

  }

  return (
    <SchemaForm schema={schema}>
      <Item field="user" />
    </SchemaForm>
  )
}

export default Demo
